<template>
    <!--    :placeholder="placeholder"-->
    <el-input
        v-model="currentValue"
        :placeholder="placeholder"
        :clearable="clearable"
        @input="handleInputValue"
        @change="handleChangeValue"
        @keyup.enter.native="$emit('keyup.enter.native')"
    />
</template>

<script>
import {isNullOrUndefined, safeGet} from "../../../../core";

export default {
    name: "SksFilterParamInput",
    props:{
        clearable: Boolean,
        placeholder: String,
        //form表单数据
        formData:[Object],
        //属性名
        propName:[String],
    },
    watch:{
        formData:{
            handler(val){
                if(isNullOrUndefined(this.formData)){
                    this.currentValue=undefined
                    return
                }
                if(isNullOrUndefined(this.propName)) {
                    this.currentValue=undefined
                    return
                }
                if(safeGet(this.formData,this.propName)!=this.currentValue){
                    this.currentValue=this.formData[this.propName]
                }
            },
            immediate: true,
            deep: true,
        }
    },
    data(){
        return {
            //
            currentValue: undefined,
        }
    },
    methods:{
        handleInputValue(){
            this.handleChangeValue()
        },
        handleChangeValue(){
            console.log("handleChangeValue",this.formData,this.propName,this.currentValue)
            if(isNullOrUndefined(this.formData)){
                return
            }
            if(isNullOrUndefined(this.propName)) {
                return
            }
            this.formData[this.propName]=this.currentValue
        },
    }

}
</script>

<style scoped>

</style>

<!--
                            <sksFilterParamInput :formData="queryParams.sksParams"
                                      :propName="item.prop"
                                      :placeholder="item.placeholder"
                                      :clearable="item.clearable"
                                      @keyup.enter.native="handleQuery"
                            >
                            </sksFilterParamInput>

-->
